﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>售后店铺查询</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline layui-col-lg2">
                        <label class="layui-form-label">店铺名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="txt_username" id="txt_username" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline layui-col-lg2">
                        <label class="layui-form-label">开始日期</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="ksrq" placeholder="yyyy-MM-dd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline layui-col-lg2">
                        <label class="layui-form-label">结束日期</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="jsrq" placeholder="yyyy-MM-dd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline layui-col-lg2">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="sel_zt" id="sel_zt">
                                <option value="">全部</option>
                                <option value="1" selected>正常营业</option>
                                <option value="2">疫情原因闭店</option>
                                <option value="3">其他原因闭店</option>
                                <option value="0">未上报</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button type="button" lay-submit="" class="layui-btn layui-btn-warm" id="exportExcel" name="exportExcel">
                            <i class="layui-icon"></i>导出Excel
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">

                <script type="text/html" id="buttonTpl">
                    {{#  if(d.statusid == "1"){ }}
                    <button class="layui-btn layui-btn-xs layui-btn-xs">正常营业</button>
                    {{#  } else if(d.statusid == "2"){ }}
                    <button class="layui-btn layui-btn-danger layui-btn-xs">疫情原因闭店</button>
                    {{#  } else if(d.statusid == "3"){ }}
                    <button class="layui-btn layui-btn-danger layui-btn-xs">疫情原因闭店</button>
                    {{#  } else { }}
                    <button class="layui-btn layui-btn-primary layui-btn-xs">未上报</button>
                    {{#  } }}
                </script>

                <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
                <script type="text/html" id="imgTpl">
                    <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
                </script>
            </div>
        </div>
    </div>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/js/cookie.js"></script>
    <script src="../../../layuiadmin/layui/layui_exts/excel.js"></script>
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'laydate', 'useradmin', 'table'], function () {
            var $ = layui.$
                , form = layui.form
                , laydate = layui.laydate
                , excel = layui.excel
                , table = layui.table;
            //导出
            $('#exportExcel').on('click', function () {
                //save('select');
                // 模拟从后端接口读取需要导出的数据
                $.ajax({
                    url: 'ashx/list.ashx?type=get_excelinfo&txt_username=' + $('#txt_username').val() + '&ksrq=' + $('#ksrq').val()
                        + '&jsrq=' + $('#jsrq').val() + '&sel_zt=' + $('#sel_zt').val()
                    , dataType: 'json'
                    , success(res) {
                        let coltitle = {
                            billdate: "日期", userid: "店铺编号", username: "店铺名称", name: "状态",
                            colseStartTime: "闭店开始日期", colseEndTime: "闭店结束日期", colseCause: "闭店原因",
                            reporttime: "上报时间", createtime: "创建日期"
                        };
                        var data = res.data;
                        //console.log(res);
                        // 重点！！！如果后端给的数据顺序和映射关系不对，请执行梳理函数后导出
                        data = excel.filterExportData(data, ['billdate', 'userid', 'username', 'name',
                            'colseStartTime', 'colseEndTime', 'colseCause', 'reporttime', 'createtime']);
                        // 重点2！！！一般都需要加一个表头，表头的键名顺序需要与最终导出的数据一致
                        data.unshift(coltitle);
                        var timestart = Date.now();
                        excel.exportExcel(data,'店铺状态' + timestart + '.xlsx', 'xlsx');
                    }
                    , error() {
                        layer.alert('获取数据失败，请检查是否部署在本地服务器环境下');
                    }
                });
            });

            // 格式化日期格式为 xxxx-xx-xx
            function getFullDate(targetDate) {
                var D, y, m, d;
                if (targetDate) {
                    D = new Date(targetDate);
                    y = D.getFullYear();
                    m = D.getMonth() + 1;
                    d = D.getDate();
                } else {
                    y = fullYear;
                    m = month;
                    d = date;
                }
                m = m > 9 ? m : '0' + m;
                d = d > 9 ? d : '0' + d;
                return y + '-' + m + '-' + d;
            };
            var nowDate = new Date();
            var fullYear = nowDate.getFullYear();
            var month = nowDate.getMonth() + 1; // getMonth 方法返回 0-11，代表1-12月
            var endOfMonth = new Date(fullYear, month, 0).getDate(); // 获取本月最后一天
            var endDate = getFullDate(nowDate.setDate(endOfMonth));//当月最后一天
            var startDate = getFullDate(nowDate.setDate(1));//当月第一天
            //加载日期控件
            laydate.render({
                elem: '#ksrq'
                , value: startDate
            });
            laydate.render({
                elem: '#jsrq'
            });

            ////验证用户是否登录
            //if ($.cookie("loginid") == "" || $.cookie("loginid") == null || $.cookie("loginid") == "null" || $.cookie("loginid") == undefined || $.cookie("loginid") == "undefined") {
            //    $.removeCookie("id", { path: "/", sucue: true });//用户id
            //    $.removeCookie("loginid", { path: "/", sucue: true });//登录账号
            //    $.removeCookie("username", { path: "/", sucue: true });//用户名
            //    $.removeCookie("role", { path: "/", sucue: true });//权限
            //    window.location.href = "user/login.html";
            //}
            //加载表格
            table.render({
                elem: '#LAY-user-manage'
                , id: 'testReload'//容器的ID
                , url: 'ashx/list.ashx?type=getlist'
                , toolbar: '#test-table-radio-toolbarDemo'
                , method: 'post'
                , page: true
                , limits: [10, 20, 30]
                , limit: 10
                , cols: [[
                    { type: 'checkbox' }
                    , { field: 'id', title: 'id', hide: true }
                    , { field: 'billdate', width: 110, title: '日期', align: 'center' }
                    , { field: 'userid', width: 100, title: '店铺编号', align: 'center' }
                    , { field: 'username', width: 150, title: '店铺名称', align: 'center' }
                    , { field: 'statusid', width: 120, title: '营业状态', align: 'center', templet: '#buttonTpl' }
                    , { field: 'colseStartTime', width: 120, title: '闭店开始日期', align: 'center' }
                    , { field: 'colseEndTime', width: 120, title: '闭店结束日期', align: 'center' }
                    , { field: 'colseCause', width: 220, title: '闭店原因', align: 'center' }
                    , { field: 'reporttime', width: 160, title: '上报时间', align: 'center' }
                    , { field: 'createtime', width: 160, title: '创建时间', align: 'center', sort: true }
                ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
                , where: {
                    txt_username: $('#txt_username').val(),
                    ksrq: $('#ksrq').val(),
                    jsrq: $('#jsrq').val(),
                    sel_zt: $('#sel_zt').val()
                }
            });
            //监听排序
            table.on('sort(LAY-user-manage)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                table.reload('testReload', {//刷新列表
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                    , where: { //请求参数
                        field: obj.field //排序字段
                        , order: obj.type //排序方式
                        , txt_username: $('#txt_username').val()
                        , ksrq: $('#ksrq').val()
                        , jsrq: $('#jsrq').val()
                        , sel_zt: $('#sel_zt').val()
                    }
                });
            });

            //监听搜索
            form.on('submit(LAY-user-front-search)', function (data) {
                var field = data.field;
                //执行重载
                table.reload('testReload', {
                    where: {
                        txt_username: $('#txt_username').val(),
                        ksrq: $('#ksrq').val(),
                        jsrq: $('#jsrq').val(),
                        sel_zt: $('#sel_zt').val()
                    }, page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
            function getRowFexId(value) {
                var checkStatus = table.checkStatus('testReload')
                    , data = checkStatus.data, arr = new Array();;
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i][value]);
                }
                return arr.join(",");
            }
            $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</body>
</html>
